﻿package core.ui.dialogs
{
    import core.ui.controls.*;
    import flash.events.*;

    public class LostPasswordDialog extends Dialog
    {
        var email:TextInput;
        var password:TextInput;
        var message:Literal;

        public function LostPasswordDialog(param1:Tuyitu)
        {
            super(param1, "rm_lost_password", 240, 185, true);
            var _loc_2:* = new Literal("rm_lost_password_desc");
            _loc_2.multiline = true;
            _loc_2.wordWrap = true;
            _loc_2.x = 18;
            _loc_2.y = 25;
            _loc_2.width = 200;
            addChild(_loc_2);
            var _loc_3:* = new Literal("rm_email");
            _loc_3.x = 18;
            _loc_3.y = 83;
            addChild(_loc_3);
            this.email = new TextInput(200, 800, "");
            this.email.value = U.GetLocalData("email");
            this.email.x = 20;
            this.email.y = 100;
            addChild(this.email);
            this.message = new Literal("rm_working", true);
            this.message.x = 25;
            this.message.y = 155;
            this.message.visible = false;
            this.message.width = 200;
            addChild(this.message);
            param1.stage.focus = this.email.t;
            return;
        }// end function

        override public function OKClick(event:MouseEvent) : void
        {
            if (this.email.value == "")
            {
                new AlertDialog(ed, "rm_insert_data");
            }
            else
            {
                var _loc_2:Boolean = false;
                cancel.visible = false;
                ok.visible = _loc_2;
                this.message.visible = true;
                U.CallHome("lost_password", {email:this.email.value}, this.Callback);
            }
            return;
        }// end function

        override public function CloseClick(event:MouseEvent) : void
        {
            Close();
            ed.CheckToShowSplash();
            return;
        }// end function

        public function Callback(message:Object) : void
        {
            var _loc_2:Boolean = true;
            cancel.visible = true;
            ok.visible = _loc_2;
            this.message.visible = false;
            if (message.success)
            {
                U.Log("rm_lost_password");
                Close();
                ed.cm.Login();
                new AlertDialog(ed, U.RM("rm_lost_password_mail_sent"));
            }
            else
            {
                switch(message.payload.toLowerCase())
                {
                    case "err:email_not_found":
                    {
                        new AlertDialog(ed, "rm_email_do_not_exist");
                        break;
                    }
                    default:
                    {
                        new AlertDialog(ed, "rm_error");
                        break;
                    }
                }
                ed.stage.focus = this.email.t;
            }
            return;
        }// end function

    }
}
